# Maintainer: Julien Voisin <julien.voisin@dustri.org>
# Contributor: Peter Bui <pnutzh4x0r@gmail.com>
pkgname=py3-pygments
pkgver=2.17.2
pkgrel=0
pkgdesc="Syntax highlighting package written in Python"
url="https://pygments.org/"
arch="noarch"
license="BSD-2-Clause"
depends="python3"
makedepends="py3-setuptools py3-gpep517 py3-wheel py3-installer"
checkdepends="py3-pytest py3-lxml py3-wcag-contrast-ratio"
subpackages="$pkgname-pyc $pkgname-doc"
source="https://files.pythonhosted.org/packages/source/P/Pygments/pygments-$pkgver.tar.gz
	build-with-setuptools.patch
	"
builddir="$srcdir/pygments-$pkgver"
options="!check" # causes issues when bootstrapping (py3-pytest depends on this)

replaces="py-pygments" # Backwards compatibility
provides="py-pygments=$pkgver-r$pkgrel" # Backwards compatibility

# secfixes:
#   2.7.4-r0:
#     - CVE-2021-20270

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	python3 -m venv --clear --without-pip --system-site-packages .testenv
	.testenv/bin/python3 -m installer .dist/*.whl
	.testenv/bin/python3 -m pytest
}

package() {
	python3 -m installer -d "$pkgdir" \
		.dist/Pygments*.whl

	mkdir -p "$pkgdir"/usr/bin
	ln -s pygmentize "$pkgdir"/usr/bin/pygmentize-3
}

doc() {
	local destdir="$subpkgdir/usr/share/doc/$pkgname"

	cd "$builddir"

	install -m 644 -D doc/pygmentize.1 \
		"$subpkgdir"/usr/share/man/man1/pygmentize.1

	mkdir -p "$destdir"
	cp AUTHORS CHANGES LICENSE "$destdir"/

	# Note: The documentation in the doc directory needs to be generated
	# by py-sphinx
	cp -R ./doc/docs/* "$destdir"/

	default_doc
}

sha512sums="
a3408a21f4c0a9f1a81d4fae5c2924f66f1f17daf98a52c4379d6953625354f47bb8db3005e6ab09407627f592843efde12afb14e1271c1e685973eb4c238d89  pygments-2.17.2.tar.gz
132d410a0964fc27624e53c13bc72fc5b13a726752cb60ce8ab082c29ba24aba80a49a32805f942258cd10e07e334428695b4cae9ae0ddc984e934df0c2e1f08  build-with-setuptools.patch
"
